import type { VonaModulesMeta } from 'vona';
<%
function capitalizeFirstLetter(string) {
  return string.charAt(0).toUpperCase() + string.slice(1);
}

function getPascalFromSnake(input){
  return input.split("-").map(capitalizeFirstLetter).join("")
}

function getCamelFromSnake(input){
  const toReturn = getPascalFromSnake(input);
  return toReturn.charAt(0).toLowerCase() + toReturn.slice(1);
}
%>
<% for (const relativeName of moduleNames) {
  const module=modules[relativeName];
  const importName=getCamelFromSnake(relativeName);
  const importClause=`import * as ${importName} from '${module.info.fullName}';\n`;
  print(importClause);
}%>
const modules = {};

<% for (const relativeName in modules) {
    const module=modules[relativeName];
    const _package={
      version: module.package.version,
      title: module.package.title,
      description: module.package.description,
      author: module.package.author,
      vonaModule: {
        capabilities: module.package.vonaModule?.capabilities,
        fileVersion: module.package.vonaModule?.fileVersion,
      },
    };
    const importName=getCamelFromSnake(relativeName);
    const importClause=`modules['${module.info.relativeName}'] = { 
      resource: ${importName},
      name: '${module.info.relativeName}',
      info: ${JSON.stringify(module.info,null,2)},
      root: '${process.env.META_MODE==='prod'?'':module.root.replaceAll('\\','\\\\')}',
      package: ${JSON.stringify(_package,null,2)},
    };`;
    print(importClause);
}%>
<%
const clause=`export const modulesMeta = { modules, moduleNames: ${JSON.stringify(moduleNames)} } as VonaModulesMeta;`;
%>
<%=clause%>
